﻿Partial Public Class EquipmentExplorer

    Private Sub Equipment_InitNewMasterRow(ByVal sender As Object, ByVal e As InitNewRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()
        row("EquipmentId") = Guid.NewGuid
        row("InspectionRate") = 0
        row("AmortRate") = 0
        row("Capacity") = 0
    End Sub


    Public Overridable Sub AddRowParameter(sender As Object, e As System.EventArgs)
        Try
            Dim aGrid As GridExtSP = CType(sender, GridExtSP)

            Dim arow As DataRow = aGrid.MetaDataTable.NewRow()
            'assign value for the metacolumn here

            aGrid.MetaDataTable.Rows.Add(arow)
        Catch ex As Exception
            MessageWindow.ShowMessage(ex, MsgBoxStyle.Information)
        End Try
    End Sub


    ''' <summary>
    ''' This subroutine calls  Metaquery Equipment_PL_SaveToProduct 
    ''' and create an echo record of Person in Product 
    ''' the PersonID is the reference to Product.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>
    ''' Remember that an echo record to product is not enforced by a relationship on the database
    ''' This is by design to permit many diferent entity to be link to Product and permit the modules of Configuration, Production, Invnetory and Quality
    ''' to be Fonctional and Factorizable for Vertical.
    '''  </remarks>
    Private Sub Equipment_SaveToProduct(ByVal sender As Object, ByVal e As EventArgs)
        Dim aDataRow As DataRow = CType(CType(sender, DXMenuItem).Tag, DataRow)
        Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing
        Try
            'RUN on SystemBox_Master
            sqlcmd = MetaQuery.GetSPCmdByMetaName("Equipment_PL_SaveToProduct")

            sqlcmd.Parameters.Clear()
            sqlcmd.Parameters.AddWithValue("@EquipmentID", aDataRow("EquipmentID"))
            sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)

            MessageWindow.ShowMessage("Update to Product Done", MsgBoxStyle.Information)
        Catch sqlex As System.Data.SqlClient.SqlException
            Throw sqlex
        Catch ex As Exception
            Throw ex
        Finally
            If sqlcmd IsNot Nothing Then
                sqlcmd.Connection.Close()
                sqlcmd.Dispose()
            End If
        End Try



    End Sub




End Class
